package ar.com.solidussource.howmuchmobile.activities;

import android.content.Intent;
import ar.com.solidussource.howmuchmobile.activities.generic.PaginatedGenListActivity;
import ar.com.solidussource.howmuchmobile.common.entities.Province;
import ar.com.solidussource.howmuchmobile.common.exception.ServiceException;
import ar.com.solidussource.howmuchmobile.services.ProvinceRestService;

/**
 * Created with IntelliJ IDEA.
 * User: FT31270775
 * Date: 06/11/12
 * Time: 15:58
 * To change this template use File | Settings | File Templates.
 */
public class ProvinceListActivity extends PaginatedGenListActivity<Province> {

    @Override
    public String getViewTitle() {
        return "Provincias";
    }

    @Override
    public void serviceCall() throws ServiceException {
        ProvinceRestService provinceRestService = new ProvinceRestService();
        data.addAll(provinceRestService.getProvinces(pageNumber, size));
    }

    @Override
    public Integer getElementId(int position) {
        return data.get(position).getId();
    }

    @Override
    public String getElementName(int position) {
        return data.get(position).getName();
    }

    @Override
    public void onElementClick(int position) {
        Intent intent = new Intent(ProvinceListActivity.this, LocationListActivity.class);
        intent.putExtra("provinceId", data.get(position).getId());
        //intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
        startActivity(intent);
    }
}